package com.example.s01helloworld.config;

import com.example.s01helloworld.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 配置类
// @Configuration 会被 ComponentScan 扫密到

@Configuration
public class WebConfiguration {

    // 配置要创建的Bean
    @Bean
    public FilterRegistrationBean testFilterRegistration() {
        // 注册过滤器对象
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new MyFilter()); // 过滤器对象
        registration.addUrlPatterns("/*");      // 过滤范围
        registration.setName("MyFilter");      // 名字
        registration.setOrder(6);             // 先后次序
        return registration;
    }

}